#pragma once
#include "fxcc/core/graph/common/pch.h"
#include "fxcc/core/graph/common/Channel.h"

namespace fxcc
{
    namespace graph
    {
        namespace common
        {

            struct FXCC_API Animation
            {
                std::string m_Name;

                float m_Duration{0};

                float m_TicksPerSecond{ 0 };

                float m_TotalTime{0};

                std::map<std::string, Channel> m_Channels;

                bool SetAnimNode(const std::string& channel, AnimNode* animNode)
                {
                    auto it = m_Channels.find(channel);
                    if (it == m_Channels.end())
                    {
                        return false;
                    }
                    it->second.m_Entity = animNode;
                    return true;
                }

                Animation() {};

                Animation(aiAnimation* anim);

                bool HasChannel(const std::string& name) const
                {
                    auto it = m_Channels.find(name);
                    return it != m_Channels.end();
                }

                Channel* GetChanel(const std::string& name)
                {
                    if(!HasChannel(name))
                    {
                        return 0;
                    }
                    return &m_Channels[name];
                }

                fxcc::graph::common::Transform GetChannelTransform(const std::string& name, const float axis) const
                {
                    auto channelIt = m_Channels.find(name);
                    if (channelIt == m_Channels.end())
                    {
                        return fxcc::graph::common::Transform();
                    }
                    else
                    {
                        double currentTicks = axis * m_Duration;
                        auto channel = channelIt->second;
                        return channel.GetSlerpMatrix(currentTicks);
                    };
                };

                void UpdateChannelsWithAxis(float axis) 
                {
                    for (auto& [name, channel] : m_Channels)
                    {
                        channel.UpdateTransformAxis(axis);
                    }
                }
                void UpdateChannels(double tick)
                {
                    for (auto& [name, channel] : m_Channels)
                    {
                        channel.UpdateTransform(tick);
                    }
                }

             
            };
        };
    };
}